/**
 * @Author 韦建韩
 * @Date 2022/4/24
 */
package com.example.devops.Manage.threadManager;


import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class MirrorCreateThread implements Runnable {
    Logger log = LoggerFactory.getLogger(MirrorCreateThread.class);
    private String userId;
    private String gitAddr;
    private String SHELL_FILE_DIR = "/java/shell";

    public MirrorCreateThread(Integer userId, String gitAddr) {
        this.userId = Integer.toString(userId);
        this.gitAddr = gitAddr;
    }

    @SneakyThrows
    @Override
    public void run() {
        Process  p = Runtime.getRuntime().exec("/java/shell/createMirrorShell.sh" + " "+userId+" "+gitAddr);
        try {
            try {
                BufferedReader bufferedReader = new BufferedReader(
                        new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8));
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    log.info(line);
                }
        p.waitFor();
            } catch (InterruptedException ignored) {
            }

        } catch (IOException ignored) {
        }
    }
}
